package com.baiye.template.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * @author GUOZHIPENG
 * @version 1.0
 * @date 2021/8/26 16:25
 */
@Data
public class User implements UserDetails {
    private Integer id;
    private String username;
    private String password;
    private String email;
    private String phone;
    private String img;
    private Date creatTime;
    private Date updateTime;
    private List<Role> roles = new ArrayList<>();
    private List<Permission> permission = new ArrayList<>();

    @JsonIgnore
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return roles;
    }

    @JsonIgnore
    @Override//账户未过期
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override//账户未锁定
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override//证书未过期
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override//用户是否可用
    public boolean isEnabled() {
        return true;
    }
}
